<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;
class ReplyController extends CommonController {
    //列表
    public function index(){
      $reply_object = D('bbs_reply');
      $map['status'] = array('egt', '0'); // 禁用和正常状态
      $Page = new Page($reply_object->where($map)->count(),C('ADMIN_CONFIG.page_size'));
      $Page->setConfig('prev','«');
      $Page->setConfig('next','»');
      $data_list     = $reply_object
          ->where($map)
          ->order('id asc')
          ->limit($Page->firstRow.','.$Page->listRows)
          ->select();
      $this->assign('mark','content');
      $this->assign('umark','bbs_reply');
      A('list')->setMetaTitle('回复列表')
          ->setBreadCrumb(array('内容','论坛管理','回复列表'))
          ->addTopButton('resume')
          ->addTopButton('delete')
          ->addTableColumn('id','ID','number',50)
          ->addTableColumn('topic_id','主题ID','number',80)
          ->addTableColumn('user_id','用户','getuser',80)
          ->addTableColumn('content','回复内容','text','auto','false')
          ->addTableColumn('status','状态','status',60)
          ->addTableColumn('ctime','创建时间','date',120)
          ->addTableColumn('','操作','rightbtn',140,'false')
          ->setTableDataList($data_list)
          ->setTableDataPage($Page->show())
          ->addRightButton('forbid')
          ->addRightButton('delete')
          ->fetch();
    }
    //状态修改
    public function setStatus(){
        if (IS_GET) {
          $ids = I('get.ids');
          $status = I('get.status');
          $reply_object = M('bbs_reply');
          $map = array(
            'id' => array('in',$ids),
          );
          $save = array(
            'status' => $status,
          );
          $rs = $reply_object->where($map)->save($save);
          if ($rs) {
              $ajax = array(
                'status'=>1,
                'text'=>'回复状态修改成功',
                'url'=>U('index')
              );
          } else {
              $ajax = array(
                'status'=>0,
                'text'=>'回复状态修改失败',
                'url'=>''
              );
          }
          $this->ajaxReturn($ajax);
        }
    }
    //删除
    public function delete(){
        if (IS_GET) {
          $ids = I('get.ids');
          $reply_object = M('bbs_reply');
          $map = array(
            'id' => array('in',$ids),
          );
          $rs = $reply_object->where($map)->delete();
          if ($rs) {
              $ajax = array(
                'status'=>1,
                'text'=>'回复删除成功',
                'url'=>U('index')
              );
          } else {
              $ajax = array(
                'status'=>0,
                'text'=>'回复删除失败',
                'url'=>''
              );
          }
          $this->ajaxReturn($ajax);
        }
    }
}
